package com.zjdiepu.www.manage.api.system;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.core.AbstractSysUser;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.base.core.PageVo;
import com.zjdiepu.www.base.enums.type.OperateType;
import com.zjdiepu.www.common.util.CollectionInitUtil;
import com.zjdiepu.www.ibiz.system.IDpCarNumberSelectorService;
import com.zjdiepu.www.ibiz.third.IJuheCarService;
import com.zjdiepu.www.ibiz.third.IJuheSeriesService;
import com.zjdiepu.www.model.third.dto.JuheCar;
import com.zjdiepu.www.model.third.dto.JuheSeries;
import com.zjdiepu.www.model.third.ext.JuheCarExt;
import com.zjdiepu.www.model.third.ext.JuheSeriesExt;

/**      
* 项目名称：dpqc-parent-manager-system   
* 类名称：CarNumberSelector   
* 类描述：   车牌选择器
* 创建人：zhangzj
* 
* 创建时间：2017年4月19日 下午6:17:21   
* 修改人：zhangzj
* 修改时间：2017年4月19日 下午6:17:21   
* 修改备注：   
* @version V1.0     
*/ 
@RestController
@RequestMapping(value="CarNumberSelectorController", produces="application/json;charset=UTF-8")
@Api(tags = {"汽车品牌"}, produces="application/json;charset=UTF-8")
public class CarNumberSelectorController extends BaseController{

	@Resource
	private IDpCarNumberSelectorService carNumberSelectorService;
	@Resource
	private IJuheSeriesService juheSeriesService;
	@Resource
	private IJuheCarService juheCarService;
	
	/** 
	* @author zhangzj
	* @Title: queryCarNumberInfo 
	* @Description: 查询汽车系列
	* @param @param carNumber
	* @param @return    设定文件 
	* @return Map<String,Object>    返回类型 
	* @version V1.0
	* @throws 
	*/
	@ApiOperation(value = "条件查询汽车系列车型",response = JuheSeries.class, httpMethod="POST", tags={"列表"})
    @RequestMapping(value="list",method = RequestMethod.POST)
	public ApiResponse list(@ModelAttribute JuheSeriesExt juheSeriesExt){
		juheSeriesExt.notDeleted();
		PageVo page = getPage(juheSeriesExt);
		int records =juheSeriesService.countByExt(juheSeriesExt);
		page.setRecords(records);
		if (records > 0) {
            List<JuheSeries> carSeriesList = juheSeriesService.selectByExt(juheSeriesExt);
            page.setRows(carSeriesList);
        } else {
            page.setRows(CollectionInitUtil.emptyList());
        }
		 return ApiResponse.success(page);
	}
	/** 
	* @author zhangzj
	* @Title: queryCarList 
	* @Description: 条件查询汽车车型
	* @param @param juheCarExt
	* @param @return    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws 
	*/
	@ApiOperation(value = "条件查询汽车车型",response = JuheCar.class, httpMethod="POST", tags={"列表"})
	@RequestMapping(value="queryCarList",method = RequestMethod.POST)
	public ApiResponse queryCarList(@ModelAttribute JuheCarExt juheCarExt){
		String cxName=juheCarExt.getCxname();
		PageVo page = getPage(juheCarExt);
		List<String> cxnames=new ArrayList<String>();
		if(cxName!=null && cxName.contains(" ")){
			String[] cxNames=cxName.split(" ");
			for (String str : cxNames) {
				cxnames.add(str);
			}
			juheCarExt.setCxnames(cxnames);
			juheCarExt.setCxname(null);
		}else{
			juheCarExt.setCxname(cxName);
		}
		int records =juheCarService.countByExt(juheCarExt);
		page.setRecords(records);
		if (records > 0) {
            List<JuheCar> carSeriesList = juheCarService.selectByExt(juheCarExt);
            page.setRows(carSeriesList);
        } else {
            page.setRows(CollectionInitUtil.emptyList());
        }
		 return ApiResponse.success(page);
	}
	@ApiOperation(value = "修改打款名单维护", response = Boolean.class, httpMethod="POST", tags={"修改"})
    @RequestMapping(value = "modify", method = RequestMethod.POST)
    public ApiResponse modify(@ModelAttribute JuheCar juheCar) {
    	AbstractSysUser currentUser = getCurrentUser();
    	juheCar.setModifier(currentUser.getId()); //统一使用修改人和修改人名称来初始化
    	juheCar.setModifierName(currentUser.getName()); 
    	juheCarService.saveUpdateAndDelete(juheCar, OperateType.edit);
        return ApiResponse.success(true);
    }
}
